package com.dr.cmdb.core.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author rui.duan
 * @version 1.0
 * @className FiledCheckEnum
 * @description 菜单枚举
 * @date 2021-03-29 11:39
 */
@Getter
@AllArgsConstructor
public enum FiledCheckEnum {

    //检查字段是否存在
    CHECK_FILED_EXIST(0,"存在校验"),

    CHECK_FILED_NULL(1,"非空校验"),

    CHECK_FILED_SEARCH(2,"搜索校验"),

    CHECK_FILED_EDIT(3,"编辑校验"),

    CHECK_FILED_IMPORT(4,"导入校验"),

    CHECK_FILED_SORT(5,"排序校验"),

    CHECK_FILED_TYPE(6,"类型校验"),


    ;


    private Integer code;
    private String value;
    

    /**
     * 根据code获取值
     * @param code
     * @return
     */
    public static String getValueByCode(Integer code) {
        FiledCheckEnum[] values = FiledCheckEnum.values();
        for (FiledCheckEnum type : values) {
            if (type.code.equals(code)) {
                return type.value;
            }
        }
        return null;
    }

    public static List<Integer> getCodes() {
        List<Integer> codes = Lists.newArrayList();
        FiledCheckEnum[] values = FiledCheckEnum.values();
        for (FiledCheckEnum type : values) {
            codes.add(type.getCode());
        }
        return codes;
    }

    /**
     * 根据value获取code
     * @param value
     * @return
     */
    public static Integer getCodeByValue(String value) {
        FiledCheckEnum[] values = FiledCheckEnum.values();
        for (FiledCheckEnum type : values) {
            if (type.value.equalsIgnoreCase(value)) {
                return type.code;
            }
        }
        return null;
    }
}
